package com.esun.payment_api.service.impl;

import com.esun.common.utils.BlankUtils;
import com.esun.payment_api.domain.SysDictContTask;
import com.esun.payment_api.domain.SysDictContTaskExample;
import com.esun.payment_api.mapper.SysDictContTaskMapper;
import com.esun.payment_api.security.AjaxResult;
import com.esun.payment_api.service.SysDictContTaskService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("SysDictContTaskService")
public class SysDictContTaskServiceImpl implements SysDictContTaskService {

    @Resource
    SysDictContTaskMapper sysDictContTaskMapper;

    @Override
    public List<SysDictContTask> selectByExample(Short coId, String keyword, String word) {
        SysDictContTaskExample example = new SysDictContTaskExample();
        SysDictContTaskExample.Criteria criteria = example.createCriteria();
        //where条件
        criteria.andIsDeletedEqualTo("0");
        if (!BlankUtils.isBlank(coId)) {
            criteria.andCoIdEqualTo(coId);
        }
        if (!BlankUtils.isBlank(keyword) && !BlankUtils.isBlank(word)) {
            switch (keyword) {
                case "code":
                    criteria.andCodeLike("%" + word + "%");
                    break;
                case "name":
                    criteria.andNameLike("%" + word + "%");
                    break;
                case "type":
                    criteria.andTypeLike("%" + word + "%");
                    break;
                default:
                    System.out.println("输入参数有误！");
                    break;
            }
        }
        return sysDictContTaskMapper.selectByExample(example);
    }

    @Override
    public AjaxResult insertSelective(SysDictContTask record) {
        try {
            if (sysDictContTaskMapper.insertSelective(record) == 1) {
                return AjaxResult.success("添加单条成功");
            } else {
                return AjaxResult.error("添加单条失败");
            }
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    @Override
    public AjaxResult deleteById(Integer id) {
        try {
            if (sysDictContTaskMapper.deleteById(id) == 1) {
                return AjaxResult.success("删除成功");
            } else {
                return AjaxResult.error("删除失败");
            }
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    @Override
    public AjaxResult updateByPrimaryKeySelective(SysDictContTask record) {
        try {
            if (sysDictContTaskMapper.updateByPrimaryKeySelective(record) == 1) {
                return AjaxResult.success("修改成功");
            } else {
                return AjaxResult.error("修改失败");
            }
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }
}
